<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>滴答办公系统-班级新增</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/media/layui/css/layui.css" media="all">
    <script type="text/javascript" src="/media/js/jquery.min.js"></script>
</head>
<body>
<div class="layui-container" style="margin-top: 5px">
    <form class="layui-form" action="#" method="post" id="change">
        <div class="layui-form-item">
            <label class="layui-form-label">原始密码</label>
            <div class="layui-input-block">
                <input type="text" id="oldpass" lay-verify="name" autocomplete="off"
                       placeholder="请输入密码" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="password" id="password" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认新密码</label>
            <div class="layui-input-block">
                <input type="password" id="newpass"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <input class="layui-btn"  style="margin-left: 10%" type="button"  onclick="changepass()" value="确认修改">
        </div>
    </form>
</div>


<script src="/media/layui/layui.js"></script>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    var form;
    layui.use([ 'form', 'laydate' ],
        function() {
            form = layui.form, layer = layui.layer, laydate = layui.laydate;
            //日期
            laydate.render({
                elem : '#date'
            });
            initData();
        });



</script>
<script>
    //修改密码
    function changepass(){
        var currentPass = "${sessionScope.loginEmp.pass}"
        var oldPass = $("#oldpass").val()
        var password = $("#password").val()
        var newpass = $("#newpass").val()
        if (currentPass != oldPass){
            layer.msg("旧密码输入错误");
            $("#oldpass").val("")
        }else{
            if (password  == newpass){
                $.getJSON("/updatePassword",{"id":${sessionScope.loginEmp.id} ,"pass":password},function (result){
                    if (result.status == 200){
                        alert(result.message);
                        parent.location.href="/login";
                    }else{
                        layer.msg(result.message);
                    }
                } )
            }else{
                layer.msg("两次密码输入不一致!");
                 $("#password").val("")
                 $("#newpass").val("")
            }
        }
    }

</script>
</body>
</html>